package com.newtouch.bxzs.common.base.util;

import com.newtouch.bxzs.common.base.BaseException;
import org.springframework.util.StringUtils;

import java.util.Date;


/**
 * 个单查询条件--录入日期跨度校验
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/2/3 9:35</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
public class DateLengthCheckUtils {

    /**
     * 查询条件开始时间和结束时间之间跨度不能超过365天
     */
    public static void dateLengthCheck(Date startDate, Date endDate){

        if (StringUtils.isEmpty(startDate)) {
            throw new BaseException("-1","起期未选择");
        }
        if (StringUtils.isEmpty(endDate)) {
            throw new BaseException("-1","止期未选择");
        }
        long beginTime = startDate.getTime();
        long endTime = endDate.getTime();
        long time = endTime - beginTime;
        System.out.println(time+"="+endTime+"-"+beginTime);
        if(time > 31536000000L){
            throw new BaseException("-1","查询时间期间超过365天");
        }
        if(time < 0){
            throw new BaseException("-1","查询止期不能小于的查询起期");
        }
    }
}
